<?php
/**
 * #Celebrate Shieh
 *             ,%%%%%%%%,
 *           ,%%/\%%%%/\%%
 *          ,%%%\c "" J/%%%
 * %.       %%%%/ o  o \%%%
 * `%%.     %%%%    _  |%%%
 *  `%%     `%%%%(__Y__)%%'
 *  //       ;%%%%`\-/%%%'
 * ((       /  `%%%%%%%'
 *  \\    .'          |
 *   \\  /       \  | |
 *    \\/         ) | |
 *     \         /_ | |__
 *     (___________))))))) 攻城湿
 *
 *        _       _
 * __   _(_)_   _(_) __ _ _ __
 * \ \ / / \ \ / / |/ _` |'_ \
 *  \ V /| |\ V /| | (_| | | | |
 *   \_/ |_| \_/ |_|\__,_|_| |_|
 */

namespace App\Validator;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class BlogValidator
{

    use Validators;

    /**
     * 邮箱验证码
     *
     * @param Request $request
     *
     * @return \Illuminate\Support\MessageBag
     */
    public function BlogEmailCodeValidator( $request )
    {
        return Validator::make($request->all(), [
            'email' => 'required|max:30|email',
        ], [
            'email.required' => $this->getErrorCode()::message(2100),
            'email.max'      => $this->getErrorCode()::message(2101),
            'email.email'    => $this->getErrorCode()::message(2102),
        ])->errors();
    }

    /**
     * 多字段登陆
     *
     * @param Request $request
     *
     * @return \Illuminate\Support\MessageBag
     */
    public function BlogLoginValidator( $request )
    {
        return Validator::make($request->all(), [
            'username' => 'required|string|max:30',
            'password' => 'required|string',
        ], [
            'username.required' => $this->getErrorCode()::message(2118),
            'username.string'   => $this->getErrorCode()::message(2203),
            'username.max'      => $this->getErrorCode()::message(2119),
            'password.required' => $this->getErrorCode()::message(2120),
            'password.string'   => $this->getErrorCode()::message(2121),
        ])->errors();
    }

    /**
     * 邮箱验证码登陆或注册
     *
     * @param Request $request
     *
     * @return \Illuminate\Support\MessageBag
     */
    public function BlogCodeValidator( $request )
    {
        return Validator::make($request->all(), [
            'email' => 'required|email|max:30',
            'code'  => 'required|max:10',
        ], [
            'email.required' => $this->getErrorCode()::message(2100),
            'email.email'    => $this->getErrorCode()::message(2102),
            'email.max'      => $this->getErrorCode()::message(2101),
            'code.required'  => $this->getErrorCode()::message(2155),
            'code.max'       => $this->getErrorCode()::message(2103),
        ])->errors();
    }

    /**
     * 创建文章
     *
     * @param Request $request
     *
     * @return \Illuminate\Support\MessageBag
     */
    public function BlogArticleValidator( $request )
    {
        return Validator::make($request->all(), [
            'title'       => 'required|max:200',
            'category_id' => 'required',
            'parent_id'   => 'required',
        ], [
            'title.required'       => $this->getErrorCode()::message(2211),
            'title.max'            => $this->getErrorCode()::message(2212),
            'category_id.required' => $this->getErrorCode()::message(2213),
            'parent_id.required'   => $this->getErrorCode()::message(2224),
        ])->errors();
    }

    /**
     * 标签
     *
     * @param Request $request
     *
     * @return \Illuminate\Support\MessageBag
     */
    public function BlogLabelValidator( $request )
    {
        return Validator::make($request->all(), [
            'name' => 'required|max:200',
        ], [
            'name.required' => $this->getErrorCode()::message(2214),
            'name.max'      => $this->getErrorCode()::message(2215),
        ])->errors();
    }

    /**
     * 链接
     *
     * @param Request $request
     *
     * @return \Illuminate\Support\MessageBag
     */
    public function BlogLinkValidator( $request )
    {
        return Validator::make($request->all(), [
            'name' => 'required|max:200',
            'url'  => 'required|url',
        ], [
            'name.required' => $this->getErrorCode()::message(2217),
            'name.max'      => $this->getErrorCode()::message(2218),
            'url.required'  => $this->getErrorCode()::message(2202),
            'url.url'       => $this->getErrorCode()::message(2202),
        ])->errors();
    }

    /**
     * 公告
     *
     * @param Request $request
     *
     * @return \Illuminate\Support\MessageBag
     */
    public function BlogNoticeValidator( $request )
    {
        return Validator::make($request->all(), [
            'name'    => 'required|max:200',
            'content' => 'required',
        ], [
            'name.required'    => $this->getErrorCode()::message(2219),
            'name.max'         => $this->getErrorCode()::message(2220),
            'content.required' => $this->getErrorCode()::message(2221),
        ])->errors();
    }


    /**
     * 验证手机
     *
     * @param Request $request
     *
     * @return \Illuminate\Support\MessageBag
     */
    public function BlogPhoneValidator( $request )
    {
        return Validator::make($request->all(), [
            'phone' => 'required|regex:/^1[34578][0-9]{9}$/|unique:users,phone,' . $request->input('user_id') . ',id,is_show,2',
        ], [
            'phone.required' => $this->getErrorCode()::message(2123),
            'phone.regex'    => $this->getErrorCode()::message(2123),
            'phone.unique'   => $this->getErrorCode()::message(2158),
        ])->errors();
    }

    /**
     * 创建图片集锦
     *
     * @param Request $request
     *
     * @return \Illuminate\Support\MessageBag
     */
    public function BlogGalleryValidator( $request )
    {
        return Validator::make($request->all(), [
            'title'       => 'required|max:200',
            'category_id' => 'required',
        ], [
            'title.required'       => $this->getErrorCode()::message(2211),
            'title.max'            => $this->getErrorCode()::message(2212),
            'category_id.required' => $this->getErrorCode()::message(2213),
        ])->errors();
    }
}
